package cn.elead.chaos.remote.web.system.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.remote.web.system.service.IRemoteDeptService;
import cn.elead.chaos.remote.web.system.domain.SysDept;
import cn.elead.chaos.remote.web.system.domain.vo.TreeSelect;

/**
 * 部门信息
 * 
 * @author luopeng
 */
@RestController
@RequestMapping("/remote/system/dept")
public class RemoteDeptController extends BaseController {
	
	@Autowired
	private IRemoteDeptService deptService;

	/**
	 * 获取部门列表
	 */
	@GetMapping("/list")
	@RequiresPermissions("system:dept:list")
	public List<SysDept> list(SysDept dept) {
		return deptService.list(dept);
	}

	/**
	 * 根据部门编号获取详细信息
	 */
	@GetMapping(value = "/{deptId}")
	@RequiresPermissions("system:dept:list")
	public SysDept getInfo(@PathVariable Long deptId) {
		return deptService.getInfo(deptId);
	}

	/**
	 * 获取部门下拉树列表
	 */
	@GetMapping("/treeselect")
	public List<TreeSelect> treeselect(SysDept dept) {
		return deptService.treeselect(dept);
	}

	/**
	 * 加载对应角色部门列表树
	 */
	@GetMapping(value = "/roleDeptTreeselect/{roleId}")
	public List<Integer> roleDeptTreeselect(@PathVariable("roleId") Long roleId) {
		return deptService.roleDeptTreeselect(roleId);
	}

	/**
	 * 新增部门
	 */
	@PostMapping
	@RequiresPermissions("system:dept:add")
	@Log(title = "部门管理", businessType = BusinessType.INSERT)
	public int add(@Validated @RequestBody SysDept dept) {
		int insertDept = deptService.add(dept);
		return insertDept;
	}

	/**
	 * 修改部门
	 */
	@PutMapping
	@RequiresPermissions("system:dept:edit")
	@Log(title = "部门管理", businessType = BusinessType.UPDATE)
	public int edit(@Validated @RequestBody SysDept dept) {
		return deptService.edit(dept);
	}

	/**
	 * 删除部门
	 */
	@DeleteMapping("/{deptId}")
	@RequiresPermissions("system:dept:remove")
	@Log(title = "部门管理", businessType = BusinessType.DELETE)
	public int remove(@PathVariable Long deptId) {
		return deptService.remove(deptId);
	}
}
